<?php
/**
 * mpPackager is a tool which helps to create packages beeing used to deliver software.
 *
 * Usage:
 *     $ php package.php {ini_file}
 *
 * Example:
 *     $ php package.php myConfig.ini
 *
 * @category    Development
 * @package 	mpPackager
 * @author		Murat Purc <murat@purc.de>
 * @copyright   Copyright (c) 2009-2010 Murat Purc (http://www.purc.de)
 * @license     http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2
 * @version     $Id: package.php 4 2010-04-15 11:28:20Z purcaholic $
 */


################################################################################
##### Initialization

define(MPPACKAGER_DIR, str_replace('\\', '/', realpath(dirname(__FILE__) . '/')) . '/');
define(LF, "\n");

require_once(MPPACKAGER_DIR . 'lib/mpPackager.php');
require_once(MPPACKAGER_DIR . 'lib/mpPackager/Config.php');
require_once(MPPACKAGER_DIR . 'lib/mpPackager/Processor.php');
require_once(MPPACKAGER_DIR . 'lib/mpPackager/FileInfo.php');


################################################################################
##### Processing

// some output
echo LF
   . "  ########################################################################" . LF
   . "  # mpPackager, provides creation of release packages                    #" . LF
   . "  #----------------------------------------------------------------------#" . LF
   . "  # Copyright (c) 2009-2010 Murat Purc, murat@purc.de                    #" . LF
   . "  #----------------------------------------------------------------------#" . LF
   . "  # Author: Murat Purc <murat@purc.de>                                   #" . LF
   . "  ########################################################################" . LF . LF;

if (!isset($_SERVER['argv']) || count($_SERVER['argv']) < 2) {
    echo "Call this script as follows:\n"
       . "$ php package.php myConfig.ini\n";
    return 1;
}

array_shift($_SERVER['argv']);
$cfgIni = $_SERVER['argv'][0];

try {

    // create configuration instance
    $cfg = new mpPackager_Config($cfgIni);

    // create packager instance
    $packager = new mpPackager(array(
        'ignoreFiles'  => $cfg->get('ignoreFiles'),
        'ignoreDirs'   => $cfg->get('ignoreDirs'),
        'replacements' => $cfg->get('replacements'),
        'replaceExts'  => $cfg->get('replaceExts'),
        'folderPerms'  => $cfg->get('folderPerms'),
        'filePerms'    => $cfg->get('filePerms')
    ));

    // set source and destination
    $packager->setSource($cfg->get('source'));
    $packager->setDestination($cfg->get('destination'));

    // create processor instance, set object and invoke the job...
    $processor = new mpPackager_Processor();
    $processor->setConfig($cfg);
    $processor->setPackager($packager);
    $processor->run();

} catch (mpPackagerException $e) {
    echo "ERROR: " . $e->getMessage();
}


echo LF
   . "  ########################################################################" . LF
   . "  # Job well done!                                                       #" . LF
   . "  ########################################################################" . LF . LF;

return 1;
